package com.gmrz.webauthn.protocol.v1.schema;


import com.gmrz.uaf.crypto.CryptoConstants.UAFAlgSign;

public enum SignAlgorithmIdentifier {
    ES256("ES256", UAFAlgSign.UAF_ALG_SIGN_SECP256R1_ECDSA_SHA256_DER.getSuite(), -7L),
    ES384("ES384", UAFAlgSign.UAF_ALG_SIGN_SECP256R1_ECDSA_SHA384_DER.getSuite(), -35L),
    ES512("ES512", UAFAlgSign.UAF_ALG_SIGN_SECP256R1_ECDSA_SHA512_DER.getSuite(), -36L),

    RS256("RS256", UAFAlgSign.UAF_ALG_SIGN_RSASSA_PKCS1_SHA256_RAW.getSuite(), -257L),
    RS384("RS384", UAFAlgSign.UAF_ALG_SIGN_RSASSA_PKCS1_SHA384_RAW.getSuite(), -258L),
    RS512("RS512", UAFAlgSign.UAF_ALG_SIGN_RSASSA_PKCS1_SHA512_RAW.getSuite(), -259L),

    PS256("PS256", UAFAlgSign.UAF_ALG_SIGN_RSASSA_PSS_SHA256_RAW.getSuite(), -37L),
    PS384("PS384", UAFAlgSign.UAF_ALG_SIGN_RSASSA_PSS_SHA384_RAW.getSuite(), -38L),
    PS512("PS512", UAFAlgSign.UAF_ALG_SIGN_RSASSA_PSS_SHA512_RAW.getSuite(), -39L),

    RS1("RS1", UAFAlgSign.UAF_ALG_SIGN_RSASSA_PKCS1_SHA1_RAW.getSuite(), -65535L);


    private String value;
    private int signAlgID;
    private long coseAlgID;

    SignAlgorithmIdentifier(String value) {
        this.value = value;
        this.signAlgID = -1;
    }

    SignAlgorithmIdentifier(String value, int signAlgID, long coseAlgID) {
        this.value = value;
        this.signAlgID = signAlgID;
        this.coseAlgID = coseAlgID;
    }

    public long getCoseAlgID() {
        return this.coseAlgID;
    }

    public String getValue() {
        return this.value;
    }

    public int getSignAlgID() {
        return this.signAlgID;
    }

    public static SignAlgorithmIdentifier forName(String name) {
        for (SignAlgorithmIdentifier alg : values()) {
            if (alg.getValue().equalsIgnoreCase(name)) {
                return alg;
            }
        }
        throw new IllegalArgumentException("Invalid algorithm identifier: " + name);
    }

    public static SignAlgorithmIdentifier forCoseAlgID(long coseAlgID) {
        for (SignAlgorithmIdentifier alg : values()) {
            if (alg.getCoseAlgID() == coseAlgID) {
                return alg;
            }
        }
        throw new IllegalArgumentException("Invalid cose alg identifier: " + coseAlgID);
    }

    public static SignAlgorithmIdentifier forSignAlgID(int signAlgID) {
        for (SignAlgorithmIdentifier identifier : values()) {
            if (identifier.getSignAlgID() == signAlgID) {
                return identifier;
            }
        }
        throw new IllegalArgumentException("Invalid UAFAlgSign: " + signAlgID);
    }

    public String toString() {
        return this.value;
    }
}
